Promise.any = function (promises) {
  return new Promise((resolve, reject) => {
    let errIdx = 0;
    promises.forEach((promise) => {
      promise.then(
        (val) => {
          resolve(val);
        },
        (err) => {
          if (++errIdx === promises.length) {
            reject();
          }
        }
      );
    });
  });
};

const promises = [1, 2, 3, 4, 5].map(
  (v) =>
    new Promise((resolve, reject) => {
      reject(v);
    })
);

Promise.any(promises).then(
  (v) => {
    console.log(v);
  },
  (e) => {
    console.log("fail");
  }
);
